#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
调试用户案例 - 找出错误的根本原因

用户案例：
1. "[Thz.la]juy-256.mp4" → 正确结果应该是 "juy-256"
2. "[psk.la]010712_252-1pon-whole1_hd.avi" → 正确结果应该是 "010712_252"  
3. "[456k.me]pppd-814.mp4" → 正确结果应该是 "pppd-814"
4. "OSR-003.wmv" → 正确结果应该是 "OSR-003"
"""

import sys
import os
sys.path.append(os.path.dirname(__file__))

from processors.cleaner import clean_single_filename
from processors.type_detector import detect_video_type, VideoType
from processors.censored_extractor import process_censored_filename
from processors.uncensored_extractor import process_uncensored_filename
from pathlib import Path

def debug_single_case(filename, expected_result):
    """调试单个案例"""
    print("\n" + "="*60)
    print("测试文件名: " + filename)
    print("期望结果: " + expected_result)
    print("="*60)
    
    # 步骤1: 分离文件名和扩展名
    file_stem = Path(filename).stem
    print("去扩展名后: " + file_stem)
    
    # 步骤2: 清理文件名
    cleaned_name = clean_single_filename(file_stem)
    print("清理后: " + cleaned_name)
    
    # 步骤3: 检测视频类型
    detected_type = detect_video_type(cleaned_name)
    print("检测类型: " + str(detected_type))
    
    # 步骤4: 尝试用对应提取器提取
    result = None
    if detected_type == VideoType.CENSORED:
        result = process_censored_filename(filename, cleaned_name)
        if result:
            standardized, metadata = result
            print("有码提取结果: " + standardized)
            print("元数据: " + str(metadata))
        else:
            print("有码提取失败")
    elif detected_type == VideoType.UNCENSORED:
        result = process_uncensored_filename(filename, cleaned_name)
        if result:
            standardized, metadata = result
            print("无码提取结果: " + standardized)
            print("元数据: " + str(metadata))
        else:
            print("无码提取失败")
    else:
        print("未识别类型，提取失败")
    
    # 结果对比
    final_result = result[0] if result else "失败"
    print("\n结果对比:")
    print("期望: " + expected_result)
    print("实际: " + final_result)
    match_result = "✅" if final_result.upper() == expected_result.upper() else "❌"
    print("匹配: " + match_result)

def main():
    """主测试函数"""
    print("用户案例调试分析")
    print("="*60)
    
    test_cases = [
        ("[Thz.la]juy-256.mp4", "juy-256"),
        ("[psk.la]010712_252-1pon-whole1_hd.avi", "010712_252"),
        ("[456k.me]pppd-814.mp4", "pppd-814"),
        ("OSR-003.wmv", "OSR-003"),
    ]
    
    for filename, expected in test_cases:
        debug_single_case(filename, expected)

if __name__ == "__main__":
    main()